package com.GainLoop.Api;

import org.alexd.jsonrpc.JSONRPCException;
import org.json.JSONException;

import com.GainLoop.Api.Entity.User;

public class Users extends ApiAbstract {


	public ApiResponseObject<User> create(User user) throws JSONException, JSONRPCException
	{
		if(user.getId() != 0) {
			throw new ApiException("user id must not set");
		}
		if(user.getFbId() == 0) {
			throw new ApiException("user fbId must be set");
		}
		if(user.getEmail() == null || user.getEmail().length() < 5) {
			throw new ApiException("user email must be set");
		}
		 
		return new ApiResponseObject<User>(GetClient().callJSONObject("users.create", user.toObject()), User.class);
	}
	
	public ApiResponseObject<User> getById(long id) throws JSONException, JSONRPCException
	{
		return new ApiResponseObject<User>(GetClient().callJSONObject("users.getById", id), User.class);
	}
	
	public ApiResponseObject<User> getByFbId(long fbId) throws JSONException, JSONRPCException
	{
		return new ApiResponseObject<User>(GetClient().callJSONObject("users.getByFbId", fbId), User.class);
	}
	
	public ApiResponseObject<User> getByEmail(String email) throws JSONException, JSONRPCException
	{
		return new ApiResponseObject<User>(GetClient().callJSONObject("users.getByEmail", email), User.class);
	}
	
}
